<template>
  <div class="login">
    <n-card
      :bordered="false"
      size="large"
      class="login-card"
    >
      <n-form
        :model="account"
        :rules="rules"
        ref="formRef"
        label-placement="left"
        :label-width="80"
        size="large"
        class="login-form"
      >
        <h3 class="title">
          后台管理系统
        </h3>

        <n-form-item path="username">
          <n-input
            placeholder="账号"
            v-model:value="account.username"
          >
            <template #prefix>
              <svg-icon icon-class="user" />
            </template>
          </n-input>
        </n-form-item>
        <n-form-item path="password">
          <n-input
            v-model:value="account.password"
            type="password"
            placeholder="密码"
            show-password-on="mousedown"
          >
            <template #prefix>
              <svg-icon icon-class="password" />
            </template>
          </n-input>
        </n-form-item>
        <n-form-item>
          <n-button
            class="submit"
            @click="handleValidateButtonClick"
            type="info"
          >
            登录
          </n-button>
        </n-form-item>
      </n-form>
    </n-card>
    <div class="login-footer">
      Copyright © 2018-2021
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { useMessage } from 'naive-ui'
import type { FormInst } from 'naive-ui'

const formRef = ref<(HTMLElement & FormInst) | null>(null)
const message = useMessage()
// const size = ref('medium')
const account = ref({ username: '', password: '' })

const rules = {
  username: [
    { required: true, trigger: 'blur', message: '请输入您的账号' }
  ],
  password: [
    { required: true, trigger: 'blur', message: '请输入您的密码' }
  ]
}

const handleValidateButtonClick = (e: Event) => {
  e.preventDefault()
  if (!formRef.value) return
  formRef.value.validate((errors) => {
    if (!errors) {
      message.success('验证成功')
    } else {
      message.success('验证失败')
    }
  })
}

</script>

<style lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url(../../assets/images/login-background.jpg);
  background-size: cover;
}

.login-card {
  width: 400px;
}

.login-form {
  border-radius: 6px;
  // background: #fff;
  // width: 400px;
  padding: 25px 25px 5px 25px;

  .title {
    margin: 0 auto 30px auto;
    text-align: center;
    // color: #707070;
  }

  .submit {
    width: 100%;
  }
}

.login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0px;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
</style>
